<template>
	<view class="page">
		<image class="bgImg" :src="imgBaseUrl+'/images/msg/bg.png'" mode=""></image>
		<view class="pageContent">
			<view class="btn" @click="goPage('/pages/componentsA/switchBind/switchBind')">
				{{language.message.changAccount}}
			</view>
				<scroll-view scroll-x="true" style="width: 690rpx;height: 140rpx;" >
					<view class="messageTab">
						<view :class="activeTab==item.id ? 'activeTab tabItem':'tabItem'" v-for="(item,index) in tabArr" :key="index" @click="changeTab(item.id)">
							{{item.text}}
						</view>
					</view>
				</scroll-view>
				<view class="contentBox" v-if="activeTab==0">
					<div class="contentItem" v-for="(item,index) in noticeArr" :key="index" @click="handleItem(item)">
						<u-image class="cover" :showLoading="true"  src="/static/images/message.png" shape="circle" width="90rpx" height="90rpx"></u-image>
						<view class="text">{{item.titile}}</view>
						<view class="date">
							{{item.sendTime}}
						</view>
						<!-- <u-icon name="arrow-right" size="26" color="#0072e5"></u-icon> -->
					</div>
				</view>
				<view class="contentBox" v-if="activeTab==1">
					<div class="contentItem" v-for="(item,index) in list" :key="index" @click="handleItem(item)">
						<u-image class="cover" :showLoading="true"  :src="imgBaseUrl3+item.snapLink" shape="circle" width="90rpx" height="90rpx"></u-image>
						<view class="text">{{item.personName}}在{{item.deviceName}}{{item.accessMethod==1?'刷脸':'刷卡'}}</view>
						<view class="date">
							{{item.accessDate}}
						</view>
						<u-icon name="arrow-right" size="26" color="#0072e5"></u-icon>
					</div>
				</view>
				<view class="contentBox" v-if="activeTab==2">
					<div class="contentItem" v-for="(item,index) in list" :key="index" @click="handleItem(item)">
						<u-image class="cover" :showLoading="true"  :src="imgBaseUrl3+item.snapLink" shape="circle" width="90rpx" height="90rpx"></u-image>
						<view class="text">{{item.personName?item.personName:''}}在{{item.deviceName}}{{item.accessMethod_dictText}}</view>
						<view class="date">
							{{item.accessDate}}
						</view>
						<!-- <u-icon name="arrow-right" size="26" color="#0072e5"></u-icon> -->
					</div>
				</view>
		</view>
	
	</view>
		
		
</template>

<script>
	function deepCopy(obj){
		return JSON.parse(JSON.stringify(obj))
	}
	import {acAccessRecordListApi} from '@/common/api/commonApi/safeApi.js'
	import {dormDeviceAccessRecordListApi,enterRoomRecordApi} from '@/common/api/commonApi/dormApi.js'
	import {getMemberApi,annountCementListApi} from '@/common/api/commonApi/commonApi.js'
	import base from '@/common/config'
	export default {
		data() {
			return {
				pageItem:[],
				selectInfoAccount: uni.getStorageSync('selectInfoAccount'),
				activeTab: 0,
				tabArr:[
					{
						id: 0,
						text: '公告'
					},
					{
						id:1,
						text: '出入记录'
					},
					// {
					// 	id:2,
					// 	text: '归寝记录'
					// },
				],
				noticeArr: [ ],
				list:[],
				isTeacher: uni.getStorageSync('isTeacher'),
				params:{
					pageNo: 1,
					pageSize: 6
				},
			}
		},
		methods: {
			getNotice(){
				annountCementListApi({
					column:'createTime',
					order:'desc',
					sendStatus : 3,
				}).then(res=>{
					this.noticeArr = res.result.records
				})
			},
			handleItem(item){
				if(this.activeTab==1){
					// this.goPage('/pages/componentsC/safe/accessRecordDetail',{item:JSON.stringify(item)})
					this.goPage('/pages/componentsC/safe/accessRecordDetail',{id:item.id})
				}else{
					
				}
			},
			changeTab(id){
				console.log(id);
				this.activeTab = id
				this.pageNo = 1
				this.getList()
			},
			selectConfirm(e){
				console.log(e);
				let merchNo = e.value[0].id
				this.selectMerchShow = false
				this.goPage('/pages/componentsC/dingcanMan/dingcanMan',{
					merchNo
				})
			},
			bindAccount(){
				uni.showModal({
					content: '暂未绑定账号信息，是否进行绑定',
					success: (res) => {
						if(res.confirm){
							this.goPage('/pages/componentsA/bingInfo/bingInfo')
						}
					}
				})
			},
			handleGoPage(url){
				let info = uni.getStorageSync('selectInfoAccount')
				if(!info){
					this.bindAccount()
				}else{
					if(url=='/pages/componentsC/dingcanMan/dingcanMan'){
						this.selectMerchShow = true
					}else if(url=='/pages/componentsC/dingcanMan/cancelOrder' || url=='/pages/componentsC/dropClass/dropClassList'){
						// 退餐记录
						let isTeacher = this.isTeacher
						this.goPage(url,{isTeacher})
					}else{
						this.goPage(url)
					}
				}
			},
			getDormList(){
				let params = this.params
				if(this.isTeacher==2){
					params.personId = this.selectInfoAccount.id
					enterRoomRecordApi(params).then(res=>{
						if(params.pageNo==1) this.list = []
						this.list = this.list.concat(res.result.records)
						this.total = res.result.total
					})
					return
				}else{
					dormDeviceAccessRecordListApi(params).then(res=>{
						if(params.pageNo==1) this.list = []
						this.list = this.list.concat(res.result.records)
						this.total = res.result.total
					})
				}
			},
			getList(){
				if(this.activeTab==1){
					let params = this.params
					params.personId = this.selectInfoAccount.id
					// if(this.isTeacher==2) 
					// if(this.isTeacher==1){
					// 	let tempArr = this.selectInfoAccount.positionList
					// 	let obj = {
					// 		managerType: 0
					// 	}
					// 	console.log(tempArr);
					// 	tempArr.forEach(item=>{
					// 		if(item.managerType > obj.managerType) obj = item
					// 	})
					// 	params.personDepartmentId = obj.departmentId
					// }
					params.source = 1
					
					acAccessRecordListApi(params).then(res=>{
						if(params.pageNo==1) this.list = []
						this.list = this.list.concat(res.result.records)
						// this.total = res.result.total
					})
				}else if(this.activeTab==2){
					this.getDormList()
				}else if(this.activeTab==0){
					this.getNotice()
				}
				
			},
			getRemberInfo(){
				let selectInfoAccount = uni.getStorageSync('selectInfoAccount')
				return getMemberApi({
					memberId : selectInfoAccount.id ? selectInfoAccount.id : ''
				}).then(res=>{
					this.selectInfoAccount = res.data[0]
					// if(this.selectInfoAccount.memberGroup=='教职工'){
					// 	this.isTeacher = 1 
					// } else{
					// 	this.isTeacher = 2
					// }
					if(this.selectInfoAccount.imageInfo) this.selectInfoAccount.imageInfo = this.selectInfoAccount.imageInfo.replace(/[\r\n]/g,"")
					uni.setStorageSync('selectInfoAccount',this.selectInfoAccount)
					this.infoItem[0].val = this.selectInfoAccount.memberNo
					this.infoItem[1].val =   this.selectInfoAccount.subsidiaryName
					this.infoItem[2].val = this.selectInfoAccount.memberName
					this.infoItem[3].val = this.selectInfoAccount.memberPhone
					uni.setStorageSync('token',res.tokenObj.token)
				}).catch(err=>{
					console.log(err);
					if(err.code==50 && err.msg == '该微信没有绑定'){
						this.bindAccount()
					}
				})
			}
		},
		onLoad() {
			this.setPageTitle(this.language.message.title)
			this.tabArr[0].text = this.language.message.btn1
			this.tabArr[1].text = this.language.message.btn2
			// this.tabArr[2].text = this.language.message.btn3
			// if(this.isTeacher==1){
			// 	this.tabArr.push({
			// 			id:2,
			// 			text: '系统消息推送'
			// 	})
			// }else{
			// 	this.tabArr.push({
			// 			id:3,
			// 			text: '出入记录'
			// 	})
			// 	this.tabArr.push({
			// 			id:4,
			// 			text: '归寝记录'
			// 	})
			// }
		},
		async onShow() {
			this.getList()
			// await this.getRemberInfo()
		},
	}
</script>

<style lang="scss" scoped>
	
.bg{
	position: fixed;
	top: 0;
	left: 0;
}

.page{
	background: #fff;
	height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	position: relative;
	// background: #fff;
	.pageContent{
		position: absolute;
		top: 0;
		.btn{
			position: absolute;
			top: 10rpx;
			right: 0;
			border: 2rpx solid #fff;
			border-radius: 30rpx;
			padding: 8rpx 20rpx;
			font-size: 26rpx;
			color: #fff;
			z-index: 10;
		}
		// left: 0;
	}
	.topBox{
		width: 690rpx;
		display: flex;
		// justify-content: space-between;
		height: 140rpx;
		// border-radius: 20rpx;
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		border-bottom: 2rpx solid #f1f1f1;
		margin-bottom: 25rpx;
		position: relative;
		.cover{
			height: 100rpx;
			width: 100rpx;
			border-radius: 10rpx;
		}
		.name{
			flex: 1;
			// text-align: center;
			padding-left: 50rpx;
			font-weight: 600;
		}
		
	}
	.messageTab{
		height: 140rpx;
		display: flex;
		align-items: flex-end;
		.tabItem{
			background: #ecedf1;
			color: #bcbcbe;
			padding: 10rpx 25rpx;
			margin: 15rpx 15rpx 0;
			border-radius: 30rpx;
			white-space: nowrap;
			height: 60rpx;
		}
		.activeTab{
			color: #fff !important;
			background: linear-gradient(to left, #00d973, #087dde) !important;
			// font-weight: 600;
		}
	}
	.contentBox{
		margin-top: 25rpx;
		border-top: 2rpx solid #f1f1f1;
		padding-top: 30rpx;
		.contentItem{
			width: 690rpx;
			display: flex;
			justify-content: space-between;
			height: 130rpx;
			border-radius: 75rpx;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			background: #fefefe;
			// border-bottom: 2rpx solid #f1f1f1;
			margin-bottom: 30rpx;
			.cover{
				height: 90rpx;
				width: 90rpx;
				border-radius: 10rpx;
			}
			.text{
				flex: 1;
				padding-left: 40rpx;
				    // white-space: nowrap;
				    // text-overflow: ellipsis;
				    // overflow: hidden;
			}
			.date{
				flex: 1;
				padding-left: 20px;
				color: #cacaca;
			}
		}
	}
	.bgImg{
		height: 100vh;
	}
}
</style>
